package wili.logic;

import wili.c.reg.GramarNode;

/**
 * 具体的语法实现类
 */
public class GramarNode_jsonExp extends GramarNode {
	GramarNode ret;

	public GramarNode get() {
		/*
		 * "{ObjType} eq '13' or {ObjType} eq '14'"
		 * "{=(${VDeliveryUpdate} === 'Y' || [undefined, null].includes(${DocEntry}))}"
		 * {=${view>/$EditMode/editMode}
		 * 
		 * bool=>exp bOp
		 * 
		 */
		if (ret != null)
			return ret;
		return ret = or("mExp", bracket("(", exp(), ")"), exp());
	}

	GramarNode exp() {
		return or("exp", //
				and("cp", varOrValue(), op(), varOrValue()), // cp:compare
				and("fun", ".!*\\[", varOrValues(","), "].", ".\\w+", "(", varOrValue(), ")"), //
				varOrValue());
	}

	GramarNode bracket(String L, Object exp, String R) {
		return and("lr", L, exp, R);
	}

	GramarNode varOrValue() {
		return or("varOrValue", or("var", ".!*#[^#]+#", and("var", ".!*[\\$@]?\\{", ".[^}]+", "}")), value());
	}

	GramarNode varOrValues(String deli) {
		return or("varOrValues", and("var", ".!*\\$?\\{", ".[^}]+", "}"), value()).setTimes(1, 999, deli);
	}

	GramarNode value() {// eg. 'C', 23, undefined, null
		return or("value", ".[a-zA-Z]\\w*", ".-?\\d+", ".'[-\\w]+'");// true|false is value.
	}

	GramarNode fun___(Object... funs) {
		GramarNode ret = and("fun", funs);
		return ret;
	}

	GramarNode op() {
		GramarNode ret = or("op", "===", "!==", "eq", "ne");
		return ret;
	}
}
